from django.shortcuts import render, redirect
from django.template.loader import render_to_string
from django.http import HttpResponse
from django.urls import reverse

from django.db import connection

# Create your views here.



# def index(request):
#     cursor = connection.cursor()
#     # cursor.execute
#     return render(request,'index.html')

from django.utils.timezone import now, localtime, make_aware
#
# def index(request):
#     # article = Article(title='abc',create_time=now())
#     # article.save()
#     article = Article.objects.get(pk=1)
#     create_time = article.create_time
#     return HttpResponse("success")
# from .models import Article,Category
# from datetime import datetime,date,time
#
# def index(request):
#     # 在Windows，mysql排序，大小写不敏感
#     article = Article.objects.filter(id__exact=1)
#     # article = Article.objects.filter(title_exact=None)
#     # article = Article.objects.filter(title_iexact="Hello world")
#     print(article.query)
#     print(article)
#     return HttpResponse("success")
#
# def index1(request):
#     article = Article.objects.filter(pk=1)
#     print(type(article))
#     return HttpResponse("success")
#
# def index2(request):
#     result = Article.objects.filter(title__contains='hello')
#     print(result.query)
#     return HttpResponse("success")
#
# def index3(request):
#     # articles = Article.objects.filter(id__in=[1,2,3])
#     # for article in articles:
#     #     print(article)
#
#     categroies = Category.objects.filter(article__in=[1,2,3])
#     for category in categroies:
#         print(category)
#
#     return HttpResponse("success")
#
# def index4(request):
#     # 查找id大于2的所有文章
#     # gt: greater than
#     # get: greater than equal
#     # lt: lower than
#     articles = Article.objects.filter(id__lt=2)
#     print(articles)
#     print(articles.query)
#     return HttpResponse("success")
#
# def index5(request):
#     articles = Article.objects.filter(title__endswith='hello')
#     print(articles.query)
#     print(articles)
#     return HttpResponse("success")
#
# def index6(request):
#     start_time = make_aware(datetime(year=2018,month=4,day=4,hour=17,minute=0,second=0))
#     end_time = make_aware(datetime(year=2018,month=4,day=4,hour=18,minute=0,second=0))
#     article = Article.objects.filter(create_time__range=(start_time,end_time))
#     print(article.query)
#     print(article)
#     return HttpResponse("success")
#
# def index7(request):
#     # articles = Article.objects.filter(create_time__date=datetime(year=2018,month=4,day=4))
#     # articles = Article.objects.filter(create_time__year__gte=2018)
#     articles = Article.objects.filter(create_time__time=time(hour=17,minute=10,second=27))
#     print(articles.query)
#     print(articles)
#     return HttpResponse("success")
#
# def index8(request):
#     # articles = Article.objects.filter(create_time__isnull=True)
#     articles = Article.objects.filter(title__iregex=r"^hello")
#     print(articles.query)
#     print(articles)
#     return HttpResponse("success")
